<?php
	session_start();
	$postingan = $_POST['postingan'];
	
	$simpan = nl2br($postingan);
	$len = strlen($postingan);
	$arr = array($_POST['wallowner']);
	$j = 0;	$k = 0;
	for ($i=0; $i<$len; ++$i)
		if ($postingan[$i] == "@")
		{
			if (($k==1)&&($i > $j))
				array_unshift($arr,substr($postingan, $j, $i-$j));
			$j = $i+1;$k = 1;
		}
		else if (($postingan[$i] == "\t") || ($postingan[$i] == ' ') || ($postingan[$i] == '.') || ($postingan[$i] == ',') || ($postingan[$i] == ';') || ($postingan[$i] == '!') || ($postingan[$i] == '?') || ($postingan[$i] == '-') || ($postingan[$i] == '+') || ($postingan[$i] == '/') || ($postingan[$i] == '\\') || ($postingan[$i] == '"') || ($postingan[$i] == "'") || ($postingan[$i] == ':') || ($postingan[$i] == '(') || ($postingan[$i] == ')') || ($postingan[$i] == '[') || ($postingan[$i] == ']') || ($postingan[$i] == '{') || ($postingan[$i] == '}') || ($postingan[$i] == '#') || ($postingan[$i] == '&'))
		{
			if (($k==1)&&($i > $j))
				array_unshift($arr,substr($postingan, $j, $i-$j));
			$k = 0;
			$j = $i+1;
		}
	if (($k==1)&&($i > $j))		array_unshift($arr,substr($postingan, $j, $i-$j));
	sort($arr);	$count=count($arr);
	
    require_once 'database.php';
    database::query("INSERT INTO userpost (Teks, Username, Username_Poster) VALUES ('$_POST[postingan]', '$_POST[wallowner]','$_SESSION[username]')");
	$IdPost = database::query("SELECT IDPost FROM userpost ORDER BY IDPost DESC");
	$idPost = mysql_fetch_row($IdPost);
	
	for ($i=0; $i<$count; ++$i){
		echo "yg di tag : ".$arr[$i].":<br/>";
		database::query("INSERT INTO posttag (Username, IDPost) VALUES ('$arr[$i]','$idPost[0]')");
		if ($_SESSION['username']!=$arr[$i])
			database::query("INSERT INTO notification (username, type, tagger, identifier) VALUES ('$arr[$i]',1,'$_SESSION[username]','$idPost[0]')");
	}
	$usr = $_SESSION['username'];
	
    //header("Location: ".$CFG->url."../wall.php?".$usr);
?>